#include"timer.h"
#include"stdio.h"
void timer_start(timer* tm){
    if (tm->start) return;
    tm->start = true;
    gettimeofday(&tm->tv1, NULL);
}

void timer_stop(timer* tm){
    if (!tm->start)return;
    gettimeofday(&tm->tv2, NULL);
    tm->start = false;
    tm->tmptime =(long long)((((long long)tm->tv2.tv_sec)*1000000 + tm->tv2.tv_usec) 
                         -(((long long)tm->tv1.tv_sec)*1000000 + tm->tv1.tv_usec));
    
}

void timer_stop_n_accum(timer* tm){
    if (!tm->start)return;
    timer_stop(tm);
    tm->tottime += tm->tmptime;
    printf("tottime: %lld\n", tm->tottime);
}